package com.hirstlogics.boxarrow.box;

import java.util.ArrayList;
import java.util.Iterator;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import com.hirstlogics.boxarrow.xml.Persist;

public class BoxList implements BoxHolder,Persist {
	
	ArrayList<Box> contents = new ArrayList<Box>();

	/* (non-Javadoc)
	 * @see com.hirstlogics.boxarrow.box.BoxHolder#add(com.hirstlogics.boxarrow.box.Box)
	 */
	public void add(Box newBox) {
		if (!contents.contains(newBox))
			contents.add(newBox);
	}
	
	/* (non-Javadoc)
	 * @see com.hirstlogics.boxarrow.box.BoxHolder#boxCount()
	 */
	public int boxCount() {
		return contents.size();
	}
	
	public String getName(int idx) {
		return contents.get(idx).getName();
	}
	
	public Box getBox(int idx) {
		return contents.get(idx);
	}
	
	public void render(XMLStreamWriter writer) throws XMLStreamException {
		writer.writeStartElement(Persist.PREFIX, Persist.BOXES_TAG, Persist.BOXARROW);
		for (Iterator<Box> idx = contents.iterator(); idx.hasNext();) {
			idx.next().render(writer);
		}
		writer.writeEndElement();
	}

	public String getName() {
		return "";
	}


}
